//
//  UITextField+LZExtension.m
//  百思不得姐
//
//  Created by 郝庆 on 16/5/14.
//  Copyright © 2016年 haoqing. All rights reserved.
//

#import "UITextField+LZExtension.h"

static NSString * const LZPlaceholderColorKey = @"_placeholderLabel.textColor";

@implementation UITextField (LZExtension)

- (void)setLz_placeholderColor:(UIColor *)lz_placeholderColor
{
    // 提前设置占位文字, 目的 : 让它提前创建placeholderLabel
    NSString *oldPlaceholder = self.placeholder;
    self.placeholder = @" ";
    self.placeholder = oldPlaceholder;
    
    // 恢复到默认的占位文字颜色
    if (lz_placeholderColor == nil) {
        lz_placeholderColor = [UIColor colorWithRed:0 green:0 blue:0.0980392 alpha:0.22];
    }
    
    // 设置占位文字颜色
    [self setValue:lz_placeholderColor forKeyPath:LZPlaceholderColorKey];
}

- (UIColor *)lz_placeholderColor
{
    return [self valueForKeyPath:LZPlaceholderColorKey];
}

@end
